<template>
	<view class="qj-list">

		<z-paging ref="paging" v-model="dg.list" @query="getDgList" :default-page-size="10"
			:empty-view-style="{'top': '80rpx'}" :empty-view-z-index="15"
			:paging-style="{'background-color':'#ffffff'}">

			<ListTools  slot="top" :total="dg.total" :sedate="{st: dg.ps.stime, et: dg.ps.etime}" @selDate="selSeDate">
				<template>
					<view class="other-btns">
						<label class="lt-obtn" @click=" findDgByDay()">清空时间</label>
					</view>
				</template>

			</ListTools>

			<view>
				<view class="my-list2">
					<view class="ml-item" v-for="(o, index) in dg.list" :key="index">
						<view class="i-title" :data-obj="o.id" @click="gotoQjDetail">
							<view>
								<view class="tip-icon"></view>{{o.abnormalityType == '0'?'违章':'事故'}}

							</view>
							<view>详情<u-icon name="arrow-right"></u-icon></view>
						</view>

						<view class="i-row">师傅：{{o.driverInfo}}</view>
						<view class="i-row">车牌：{{o.plateNum}}</view>
						<view v-if='o.abnormalityType != "0"' class="i-row">赔偿金额：{{o.driverIndemnityPrice?o.driverIndemnityPrice:''}}</view>
						<view v-if='o.abnormalityType == "0"' class="i-row">驾驶证扣分：{{o.subDrivePoint?o.subDrivePoint:''}}</view>
						<view v-if='o.abnormalityType == "0"' class="i-row">买分金额：{{o.buyPointPrice?o.buyPointPrice:''}}</view>
						<view v-if='o.abnormalityType == "0"' class="i-row">罚款金额：{{o.driverPunishPrice?o.driverPunishPrice:''}}</view>
						<view class="i-row">时间：{{o.abnormalityTime}}</view>

						<view class="i-footer">
							<view>
								状态：{{o.abnormalityStatus =='WAIT_DRIVER_OPER'?'待驾驶员处理':o.abnormalityStatus =='WAIT_MANAGER_CHECK'?'待管理员审核':o.abnormalityStatus =='CHECKED'?'审核通过':o.abnormalityStatus =='REFUESD'?'审核不通过':'' }}
							</view>
						</view>

						<view v-if='o.abnormalityStatus =="WAIT_DRIVER_OPER"' class="i-btns">

							<!-- <view  class="btn" :data-obj="{index: index, id: o.id}"
								@click="setDelQjMd">删除记录</view> -->

							<view class="btn ok" :data-obj="o.id" @click="gotoQjAdup">处理异常</view>
						</view>
					</view>
				</view>

				<u-modal :title="delMd.title" :confirm-style="{'color': '#00c3ce'}" v-model="delMd.state"
					:show-cancel-button="true" @confirm="okDelQj">
					<view class="c-yellow" :style="{'padding': '20rpx', 'text-align': 'center'}">{{delMd.tip}}</view>
				</u-modal>

				<u-toast ref="qtoast" />
			</view>
		</z-paging>
		<u-select @confirm="plateNum_sheet" :label-name='"plate_num"' :value-name='"plate_num"' v-model="plateNum_show"
			:list="plateNumList"></u-select>
	</view>
</template>

<script>
	import ListTools from '@/components/list-tools/list-tools.vue';

	export default {
		components: {
			ListTools
		},
		data() {
			return {
				plateNumList: [],
				plateNum_show: false,
				// 列表参数对象
				dg: {
					// 请求参数对象
					ps: {
						// 开始时间
						stime: '',
						// 结束时间
						etime: '',
						page: {
							pageNum: 1,
							pageSize: 10,
						},
						plateNum: '',
					},
					// 列表数组
					list: [],
					// 数据总数
					total: 0,
				},

				// 删除-请假-弹框
				delMd: {
					state: false,
					title: '删除提示',
					tip: '', // 提示内容
					obj: null, // 参数对象
				}
			}
		},
		onLoad() {
			const that = this;

			// 其他页面跳转回当前页刷新列表
			uni.$on('refQjList', (i) => {
				that.$nextTick(function() {
					if (that.dg.list.length == 0) {
						// 重新加载
						that.$refs.paging.reload();
					} else {
						// 刷新列表
						that.$refs.paging.refresh();
					}
				});
			});

			that.$u.api.findCarCombo({
				page: {
					pageNum: 1,
					pageSize: 999,
				},
				plateNum: '',
			}).then(res => {
				that.plateNumList = res.data.list
			});
		},
		onUnload() {
			// 移除监听
			uni.$off('refQjList', this.refQjList);
		},
		methods: {

			findDgByDay(e) {
				this.dg.ps.stime = ''
				this.dg.ps.etime = ''
				this.getDgList();
			},
			plateNum_sheet(e) {
				this.dg.ps.plateNum = e[0].value

				this.getDgList();
			},
			plateNum_btn() {
				this.plateNum_show = true
			},
			new_data() {
				let currentDate = new Date();
				let firstDayOfPreviousMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1);
				let lastDayOfPreviousMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);

				function formatDate(date) {
					let year = date.getFullYear();
					let month = String(date.getMonth() + 1).padStart(2, '0');
					let day = String(date.getDate()).padStart(2, '0');
					return `${year}-${month}-${day}`;
				}

				let formattedFirstDayOfPreviousMonth = formatDate(firstDayOfPreviousMonth);
				let formattedLastDayOfPreviousMonth = formatDate(lastDayOfPreviousMonth);
				return formattedFirstDayOfPreviousMonth
			},
			two_data() {
				let currentDate = new Date();
				let firstDayOfPreviousMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1);
				let lastDayOfPreviousMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 0);

				function formatDate(date) {
					let year = date.getFullYear();
					let month = String(date.getMonth() + 1).padStart(2, '0');
					let day = String(date.getDate()).padStart(2, '0');
					return `${year}-${month}-${day}`;
				}

				let formattedFirstDayOfPreviousMonth = formatDate(firstDayOfPreviousMonth);
				let formattedLastDayOfPreviousMonth = formatDate(lastDayOfPreviousMonth);
				return formattedLastDayOfPreviousMonth
			},
			// 日期选择事件回调
			selSeDate(e) {
				console.log('起止日期选择事件', e);

				this.dg.ps.stime = e.st.split(' ')[0];
				this.dg.ps.etime = e.et.split(' ')[0];

				// 刷新列表
				this.$refs.paging.reload();
			},

			getDgList(pageNo, pageSize) {
				let that = this,
					dg = that.dg,
					ps = dg.ps;
				that.$u.api.findVehicleAbnormalityList(ps).then(res => {
					if (res.code == 1) {
						that.$refs.paging.complete(res.data.list);

						dg.total = res.data.total;
					}
				});
			},
			// 导航-请假详情
			gotoQjDetail(e) {
				let id = e.currentTarget.dataset.obj;

				uni.navigateTo({
					url: '/my-man/violations_and_accidents/violations_and_accidents_detail/violations_and_accidents_detail?id=' +
						id
				})
			},
			// 添加/修改
			gotoQjAdup(e) {
				let id = e.currentTarget.dataset.obj;
				let url =
					'/my-man/violations_and_accidents/violations_and_accidents_adup/violations_and_accidents_adup?id=' + id


				uni.navigateTo({
					url: url
				});
			},
			// // 显示-添加/修改-请假-弹框
			// showQjAdup(e){
			// 	console.log('修改数据', e);
			// 	const that = this, U = that.U, md = that.adupQjMd, obj = e.currentTarget.dataset.obj;

			// 	// 显示弹框
			// 	md.show = true;
			// 	// 设置-修改类型
			// 	md.obj = U.scopy(obj);

			// 	console.log('修改弹框对象', that.adupQjMd);
			// },
			// 删除-请假记录
			setDelQjMd(e) {
				let that = this,
					U = that.U;

				that.delMd = {
					state: true,
					title: '删除提示',
					tip: '确定删除当前请假记录吗？',
					obj: e.currentTarget.dataset.obj
				};
			},
			// 确认删除-请假记录
			okDelQj() {
				let that = this,
					U = that.U,
					obj = that.delMd.obj;

				that.$u.api.delQj({
					id: obj.id
				}).then(res => {
					if (res.code == 1) {
						U.qsuccess('删除成功', 1000);

						// 刷新记录
						that.$refs.paging.refresh();

						// 隐藏弹框
						that.delMd.state = false;
					} else {
						U.qerror(res.msg);
					}
				});
			},


		}
	}
</script>

<style lang="less">
	.lt-btns{
		display:flex !important;
	}
	.qj-list {
		min-height: 100vh;
		padding-top: 2rpx;
	}

	.routeSimpleName {
		position: absolute;
		left: 380rpx;
		width: 200rpx;
		background: #fff;
		top: 10rpx;
		z-index: 9999;
		text-align: center;
		border-radius: 10rpx;
		border: 1px solid #00C3CE;
		color: #00C3CE;
		margin-right: 10rpx;
		display: flex;
		height: 40rpx;
		justify-content: space-between;

	}
</style>